<?xml version="1.0"?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html><head><title>SASAPI</title><script src="../../../quicknav.js" type="text/javascript"></script><script><!--
document.quicknavBasePath="../../../index-files";
//--></script><link href="../../../style.css" title="JavaDoc" rel="stylesheet" type="text/css"/><link href="../../../unnatural.css" title="Unnatural" rel="alternate stylesheet" type="text/css"/><link href="../../../overview-summary.html" title="Overview" rel="top"/><meta name="generator" content="http://www.badgers-in-foil.co.uk/projects/as2api/"/></head><body><pre><span class="lineno" id="1">     1  </span><span class="comment doc">/**
<span class="lineno" id="2">     2  </span> * com.sekati.math.MathBase
<span class="lineno" id="3">     3  </span> * @version 1.1.9
<span class="lineno" id="4">     4  </span> * @author jason m horwitz | sekati.com
<span class="lineno" id="5">     5  </span> * Copyright (C) 2007  jason m horwitz, Sekat LLC. All Rights Reserved.
<span class="lineno" id="6">     6  </span> * Released under the MIT License: http://www.opensource.org/licenses/mit-license.php
<span class="lineno" id="7">     7  </span> */</span>
<span class="lineno" id="8">     8  </span>
<span class="lineno" id="9">     9  </span><span class="key">import</span> com.sekati.math.Integer;
<span class="lineno" id="10">    10  </span>
<span class="lineno" id="11">    11  </span><span class="comment doc">/**
<span class="lineno" id="12">    12  </span> * Static class wrapping various Math utilities.
<span class="lineno" id="13">    13  </span> */</span>
<span class="lineno" id="14">    14  </span><span class="key">class</span> com.sekati.math.MathBase {			
<span class="lineno" id="15">    15  </span>
<span class="lineno" id="16">    16  </span>	<span class="comment doc">/**
<span class="lineno" id="17">    17  </span>	 * Returns the highest value of all passed arguments
<span class="lineno" id="18">    18  </span>	 * Like Math.max() but supports any number of args passed to it
<span class="lineno" id="19">    19  </span>	 * @return Number
<span class="lineno" id="20">    20  </span>	 */</span>
<span class="lineno" id="21">    21  </span>	<span class="key">public</span> <span class="key">static</span> <span class="key">function</span> max():Number {
<span class="lineno" id="22">    22  </span>		<span class="key">return</span> maxArray( arguments );
<span class="lineno" id="23">    23  </span>	}
<span class="lineno" id="24">    24  </span>
<span class="lineno" id="25">    25  </span>	<span class="comment doc">/**
<span class="lineno" id="26">    26  </span>	 * Returns the lowest value of all passed arguments
<span class="lineno" id="27">    27  </span>	 * Like Math.min() but supports any number of args passed to it
<span class="lineno" id="28">    28  </span>	 * @return Number
<span class="lineno" id="29">    29  </span>	 */</span>
<span class="lineno" id="30">    30  </span>	<span class="key">public</span> <span class="key">static</span> <span class="key">function</span> min():Number {
<span class="lineno" id="31">    31  </span>		<span class="key">return</span> minArray( arguments );
<span class="lineno" id="32">    32  </span>	}
<span class="lineno" id="33">    33  </span>
<span class="lineno" id="34">    34  </span>	<span class="comment doc">/**
<span class="lineno" id="35">    35  </span>	 * Returns the highest value of all items in array
<span class="lineno" id="36">    36  </span>	 * Like Math.max() but supports any number of items
<span class="lineno" id="37">    37  </span>	 * @param a (Array)
<span class="lineno" id="38">    38  </span>	 * @return Number
<span class="lineno" id="39">    39  </span>	 */</span>
<span class="lineno" id="40">    40  </span>	<span class="key">public</span> <span class="key">static</span> <span class="key">function</span> maxArray(a:Array):Number {
<span class="lineno" id="41">    41  </span>		<span class="key">var</span> val:Number = <span class="key">null</span>;
<span class="lineno" id="42">    42  </span>		<span class="key">for</span> (<span class="key">var</span> i <span class="key">in</span> a) {
<span class="lineno" id="43">    43  </span>			<span class="key">if</span> (a[i] &gt; val || val == <span class="key">null</span>) {
<span class="lineno" id="44">    44  </span>				val = Number( a[i] );
<span class="lineno" id="45">    45  </span>			}
<span class="lineno" id="46">    46  </span>		}
<span class="lineno" id="47">    47  </span>		<span class="key">return</span> val;
<span class="lineno" id="48">    48  </span>	}
<span class="lineno" id="49">    49  </span>
<span class="lineno" id="50">    50  </span>	<span class="comment doc">/**
<span class="lineno" id="51">    51  </span>	 * Returns the lowest value of all items in array
<span class="lineno" id="52">    52  </span>	 * Like Math.min() but supports any number of items
<span class="lineno" id="53">    53  </span>	 * @param a (Array)
<span class="lineno" id="54">    54  </span>	 * @return Number
<span class="lineno" id="55">    55  </span>	 */</span>
<span class="lineno" id="56">    56  </span>	<span class="key">public</span> <span class="key">static</span> <span class="key">function</span> minArray(a:Array):Number {
<span class="lineno" id="57">    57  </span>		<span class="key">var</span> val:Number = <span class="key">null</span>;
<span class="lineno" id="58">    58  </span>		<span class="key">for</span> (<span class="key">var</span> i <span class="key">in</span> a) {
<span class="lineno" id="59">    59  </span>			<span class="key">if</span> (a[i] &lt; val || val == <span class="key">null</span>) {
<span class="lineno" id="60">    60  </span>				val = Number( a[i] );
<span class="lineno" id="61">    61  </span>			}
<span class="lineno" id="62">    62  </span>		}
<span class="lineno" id="63">    63  </span>		<span class="key">return</span> val;
<span class="lineno" id="64">    64  </span>	}
<span class="lineno" id="65">    65  </span>
<span class="lineno" id="66">    66  </span>	<span class="comment doc">/**
<span class="lineno" id="67">    67  </span>	 * Same as Math.foor with extra argument to specify number of decimals
<span class="lineno" id="68">    68  </span>	 * @param val (Number)
<span class="lineno" id="69">    69  </span>	 * @param decimal (Number)
<span class="lineno" id="70">    70  </span>	 * @return Number
<span class="lineno" id="71">    71  </span>	 */</span>
<span class="lineno" id="72">    72  </span>	<span class="key">public</span> <span class="key">static</span> <span class="key">function</span> floor(val:Number, decimal:Number):Number {
<span class="lineno" id="73">    73  </span>		<span class="key">var</span> n:Number = Math.pow( <span class="num_const">10</span>, decimal );
<span class="lineno" id="74">    74  </span>		<span class="key">return</span> Math.floor( val * n ) / n;
<span class="lineno" id="75">    75  </span>	}	
<span class="lineno" id="76">    76  </span>
<span class="lineno" id="77">    77  </span>	<span class="comment doc">/**
<span class="lineno" id="78">    78  </span>	 * Round to a given amount of decimals
<span class="lineno" id="79">    79  </span>	 * @param val (Number)
<span class="lineno" id="80">    80  </span>	 * @param decimal (Number)
<span class="lineno" id="81">    81  </span>	 * @return Number
<span class="lineno" id="82">    82  </span>	 */</span>
<span class="lineno" id="83">    83  </span>	<span class="key">public</span> <span class="key">static</span> <span class="key">function</span> round(val:Number, decimal:Number):Number {
<span class="lineno" id="84">    84  </span>		<span class="key">return</span> Math.round( val * Math.pow( <span class="num_const">10</span>, decimal ) ) / Math.pow( <span class="num_const">10</span>, decimal );
<span class="lineno" id="85">    85  </span>	}
<span class="lineno" id="86">    86  </span>
<span class="lineno" id="87">    87  </span>	<span class="comment doc">/**
<span class="lineno" id="88">    88  </span>	 * Round to nearest .5
<span class="lineno" id="89">    89  </span>	 * @param val (Number)
<span class="lineno" id="90">    90  </span>	 * @return Number
<span class="lineno" id="91">    91  </span>	 * {@code Example:
<span class="lineno" id="92">    92  </span>	 * 	trace(MathBase.roundHalf(4.47)); // returns 4.5
<span class="lineno" id="93">    93  </span>	 * }
<span class="lineno" id="94">    94  </span>	 */</span>	
<span class="lineno" id="95">    95  </span>	<span class="key">public</span> <span class="key">static</span> <span class="key">function</span> roundHalf(val:Number):Number {
<span class="lineno" id="96">    96  </span>		<span class="key">var</span> num:String = String( Math.round( val * <span class="num_const">10</span> ) / <span class="num_const">10</span> );
<span class="lineno" id="97">    97  </span>		<span class="key">var</span> tmp:Array = num.split( <span class="str_const">"."</span> );
<span class="lineno" id="98">    98  </span>		<span class="key">var</span> integer:Object = tmp[<span class="num_const">0</span>]; 
<span class="lineno" id="99">    99  </span>		<span class="comment">// loose type since we swap from String to Number (cheap!)</span>
<span class="lineno" id="100">   100  </span>		<span class="key">var</span> decimal:Number = tmp[<span class="num_const">1</span>];
<span class="lineno" id="101">   101  </span>		<span class="key">if</span> (decimal &gt;= <span class="num_const">3</span> &amp;&amp; decimal &lt;= <span class="num_const">7</span> &amp;&amp; decimal != <span class="key">null</span>) {
<span class="lineno" id="102">   102  </span>			decimal = <span class="num_const">5</span>;
<span class="lineno" id="103">   103  </span>		} <span class="key">else</span> {
<span class="lineno" id="104">   104  </span>			<span class="key">if</span> (decimal &gt; <span class="num_const">7</span>) {
<span class="lineno" id="105">   105  </span>				integer = Number( integer ) + <span class="num_const">1</span>;
<span class="lineno" id="106">   106  </span>			}
<span class="lineno" id="107">   107  </span>			decimal = <span class="num_const">0</span>;
<span class="lineno" id="108">   108  </span>		}
<span class="lineno" id="109">   109  </span>		<span class="key">return</span> Number( integer + <span class="str_const">"."</span> + decimal );
<span class="lineno" id="110">   110  </span>	}
<span class="lineno" id="111">   111  </span>
<span class="lineno" id="112">   112  </span>	<span class="comment doc">/**
<span class="lineno" id="113">   113  </span>	 * Will constrain a value to the defined boundaries
<span class="lineno" id="114">   114  </span>	 * @param val (Number)
<span class="lineno" id="115">   115  </span>	 * @param min (Number)
<span class="lineno" id="116">   116  </span>	 * @param max (Number)
<span class="lineno" id="117">   117  </span>	 * @return Number
<span class="lineno" id="118">   118  </span>	 * {@code Examples:
<span class="lineno" id="119">   119  </span>	 * val: 20, 2 to 5    this will give back 5 since 5 is the top boundary
<span class="lineno" id="120">   120  </span>	 * val: 3, 2 to 5     this will give back 3
<span class="lineno" id="121">   121  </span>	 * }
<span class="lineno" id="122">   122  </span>	 */</span>
<span class="lineno" id="123">   123  </span>	<span class="key">public</span> <span class="key">static</span> <span class="key">function</span> constrain(val:Number, min:Number, max:Number):Number {
<span class="lineno" id="124">   124  </span>		<span class="key">if</span> (val &lt; min) {
<span class="lineno" id="125">   125  </span>			val = min;
<span class="lineno" id="126">   126  </span>		} <span class="key">else</span> <span class="key">if</span> (val &gt; max) {
<span class="lineno" id="127">   127  </span>			val = max;
<span class="lineno" id="128">   128  </span>		}
<span class="lineno" id="129">   129  </span>		<span class="key">return</span> val;
<span class="lineno" id="130">   130  </span>	}
<span class="lineno" id="131">   131  </span>
<span class="lineno" id="132">   132  </span>	<span class="comment doc">/**
<span class="lineno" id="133">   133  </span>	 * Return the proportional value of two pairs of numbers.
<span class="lineno" id="134">   134  </span>	 * @param x1 (Number)
<span class="lineno" id="135">   135  </span>	 * @param x2 (Number)
<span class="lineno" id="136">   136  </span>	 * @param y1 (Number)
<span class="lineno" id="137">   137  </span>	 * @param y2 (Number)
<span class="lineno" id="138">   138  </span>	 * @param x (Number) optional
<span class="lineno" id="139">   139  </span>	 * @return Number
<span class="lineno" id="140">   140  </span>	 */</span>
<span class="lineno" id="141">   141  </span>	<span class="key">public</span> <span class="key">static</span> <span class="key">function</span> proportion(x1:Number, x2:Number, y1:Number, y2:Number, x:Number):Number {
<span class="lineno" id="142">   142  </span>		<span class="key">var</span> n:Number = (!x) ? <span class="num_const">1</span> : x;
<span class="lineno" id="143">   143  </span>		<span class="key">var</span> slope:Number = (y2 - y1) / (x2 - x1);
<span class="lineno" id="144">   144  </span>		<span class="key">return</span> (slope * (n - x1) + y1);
<span class="lineno" id="145">   145  </span>	}
<span class="lineno" id="146">   146  </span>
<span class="lineno" id="147">   147  </span>	<span class="comment doc">/**
<span class="lineno" id="148">   148  </span>	 * Check if number is positive (zero is considered positive)
<span class="lineno" id="149">   149  </span>	 * @param n (Number)
<span class="lineno" id="150">   150  </span>	 * @return Boolean
<span class="lineno" id="151">   151  </span>	 */</span>
<span class="lineno" id="152">   152  </span>	<span class="key">public</span> <span class="key">static</span> <span class="key">function</span> isPositive(n:Number):Boolean {
<span class="lineno" id="153">   153  </span>		<span class="key">return</span> (n &gt;= <span class="num_const">0</span>);
<span class="lineno" id="154">   154  </span>	}
<span class="lineno" id="155">   155  </span>
<span class="lineno" id="156">   156  </span>	<span class="comment doc">/**
<span class="lineno" id="157">   157  </span>	 * Check if number is negative
<span class="lineno" id="158">   158  </span>	 * @param n (Number)
<span class="lineno" id="159">   159  </span>	 * @return Boolean
<span class="lineno" id="160">   160  </span>	 */</span>
<span class="lineno" id="161">   161  </span>	<span class="key">public</span> <span class="key">static</span> <span class="key">function</span> isNegative(n:Number):Boolean {
<span class="lineno" id="162">   162  </span>		<span class="key">return</span> (n &lt; <span class="num_const">0</span>);
<span class="lineno" id="163">   163  </span>	}	
<span class="lineno" id="164">   164  </span>
<span class="lineno" id="165">   165  </span>	<span class="comment doc">/**
<span class="lineno" id="166">   166  </span>	 * Check if number is Odd (convert to Integer if necessary)
<span class="lineno" id="167">   167  </span>	 * @param n (Number)
<span class="lineno" id="168">   168  </span>	 * @return Boolean
<span class="lineno" id="169">   169  </span>	 */</span>
<span class="lineno" id="170">   170  </span>	<span class="key">public</span> <span class="key">static</span> <span class="key">function</span> isOdd(n:Number):Boolean {
<span class="lineno" id="171">   171  </span>		<span class="key">var</span> i:Integer = <span class="key">new</span> Integer( n );
<span class="lineno" id="172">   172  </span>		<span class="key">var</span> e:Integer = <span class="key">new</span> Integer( <span class="num_const">2</span> );
<span class="lineno" id="173">   173  </span>		<span class="key">return</span> Boolean( i % e );	
<span class="lineno" id="174">   174  </span>	}
<span class="lineno" id="175">   175  </span>
<span class="lineno" id="176">   176  </span>	<span class="comment doc">/**
<span class="lineno" id="177">   177  </span>	 * Check if number is Even (convert to Integer if necessary)
<span class="lineno" id="178">   178  </span>	 * @param n (Number)
<span class="lineno" id="179">   179  </span>	 * @return Boolean
<span class="lineno" id="180">   180  </span>	 */</span>
<span class="lineno" id="181">   181  </span>	<span class="key">public</span> <span class="key">static</span> <span class="key">function</span> isEven(n:Number):Boolean {
<span class="lineno" id="182">   182  </span>		<span class="key">var</span> int:Integer = <span class="key">new</span> Integer( n );
<span class="lineno" id="183">   183  </span>		<span class="key">var</span> e:Integer = <span class="key">new</span> Integer( <span class="num_const">2</span> );
<span class="lineno" id="184">   184  </span>		<span class="key">return</span> (int % e == <span class="num_const">0</span>);
<span class="lineno" id="185">   185  </span>	}
<span class="lineno" id="186">   186  </span>
<span class="lineno" id="187">   187  </span>	<span class="comment doc">/**
<span class="lineno" id="188">   188  </span>	 * Check if number is Prime (divisible only itself and one)
<span class="lineno" id="189">   189  </span>	 * @param n (Number)
<span class="lineno" id="190">   190  </span>	 * @return Boolean
<span class="lineno" id="191">   191  </span>	 */</span>
<span class="lineno" id="192">   192  </span>	<span class="key">public</span> <span class="key">static</span> <span class="key">function</span> isPrime(n:Number):Boolean {
<span class="lineno" id="193">   193  </span>		<span class="key">if</span> (n &gt; <span class="num_const">2</span> &amp;&amp; n % <span class="num_const">2</span> == <span class="num_const">0</span>) <span class="key">return</span> <span class="key">false</span>;
<span class="lineno" id="194">   194  </span>		<span class="key">var</span> l:Number = Math.sqrt( n );
<span class="lineno" id="195">   195  </span>		<span class="key">for</span> (<span class="key">var</span> i:Number = <span class="num_const">3</span>; i &lt;= l ; i += <span class="num_const">2</span>) {
<span class="lineno" id="196">   196  </span>			<span class="key">if</span> (n % i == <span class="num_const">0</span>) <span class="key">return</span> <span class="key">false</span>;
<span class="lineno" id="197">   197  </span>		}
<span class="lineno" id="198">   198  </span>	}
<span class="lineno" id="199">   199  </span>
<span class="lineno" id="200">   200  </span>	<span class="comment doc">/**
<span class="lineno" id="201">   201  </span>	 * Calculate the factorial of the integer.
<span class="lineno" id="202">   202  </span>	 * @param n (Number) 
<span class="lineno" id="203">   203  </span>	 * @return Number
<span class="lineno" id="204">   204  </span>	 */</span>
<span class="lineno" id="205">   205  </span>	 
<span class="lineno" id="206">   206  </span>	<span class="key">public</span> <span class="key">static</span> <span class="key">function</span> factorial(n:Number):Number {
<span class="lineno" id="207">   207  </span>		<span class="key">if</span> (n == <span class="num_const">0</span>) <span class="key">return</span> <span class="num_const">1</span>;
<span class="lineno" id="208">   208  </span>		<span class="key">var</span> d:Number = n.valueOf( );
<span class="lineno" id="209">   209  </span>		<span class="key">var</span> i:Number = d - <span class="num_const">1</span>;
<span class="lineno" id="210">   210  </span>		<span class="key">while</span> (i) {
<span class="lineno" id="211">   211  </span>			d = d * i;
<span class="lineno" id="212">   212  </span>			i--;
<span class="lineno" id="213">   213  </span>		}
<span class="lineno" id="214">   214  </span>		<span class="key">return</span> d;
<span class="lineno" id="215">   215  </span>	}
<span class="lineno" id="216">   216  </span>
<span class="lineno" id="217">   217  </span>	<span class="comment doc">/**
<span class="lineno" id="218">   218  </span>	 * Return an array of divisors of the integer.
<span class="lineno" id="219">   219  </span>	 * @param n (Number)
<span class="lineno" id="220">   220  </span>	 * @return Number
<span class="lineno" id="221">   221  </span>	 */</span>
<span class="lineno" id="222">   222  </span>	<span class="key">public</span> <span class="key">static</span> <span class="key">function</span> getDivisors(n:Number):Array {
<span class="lineno" id="223">   223  </span>		<span class="key">var</span> r:Array = <span class="key">new</span> Array( );
<span class="lineno" id="224">   224  </span>		<span class="key">for</span> (<span class="key">var</span> i:Number = <span class="num_const">1</span>, e:Number = n / <span class="num_const">2</span>; i &lt;= e ; i++) {
<span class="lineno" id="225">   225  </span>			<span class="key">if</span> (n % i == <span class="num_const">0</span>) r.push( i );
<span class="lineno" id="226">   226  </span>		}
<span class="lineno" id="227">   227  </span>		<span class="key">if</span> (n != <span class="num_const">0</span>) r.push( n.valueOf( ) );
<span class="lineno" id="228">   228  </span>		<span class="key">return</span> r;
<span class="lineno" id="229">   229  </span>	}
<span class="lineno" id="230">   230  </span>
<span class="lineno" id="231">   231  </span>	<span class="comment doc">/**
<span class="lineno" id="232">   232  </span>	 * Check if number is an Integer
<span class="lineno" id="233">   233  </span>	 * @param n (Number)
<span class="lineno" id="234">   234  </span>	 * @return Boolean
<span class="lineno" id="235">   235  </span>	 */</span>
<span class="lineno" id="236">   236  </span>	<span class="key">public</span> <span class="key">static</span> <span class="key">function</span> isInteger(n:Number):Boolean {
<span class="lineno" id="237">   237  </span>		<span class="key">return</span> (n % <span class="num_const">1</span> == <span class="num_const">0</span>);
<span class="lineno" id="238">   238  </span>	}
<span class="lineno" id="239">   239  </span>
<span class="lineno" id="240">   240  </span>	<span class="comment doc">/**
<span class="lineno" id="241">   241  </span>	 * Check if number is Natural (positive Integer)
<span class="lineno" id="242">   242  </span>	 * @param n (Number)
<span class="lineno" id="243">   243  </span>	 * @return Boolean
<span class="lineno" id="244">   244  </span>	 */</span>
<span class="lineno" id="245">   245  </span>	<span class="key">public</span> <span class="key">static</span> <span class="key">function</span> isNatural(n:Number):Boolean {
<span class="lineno" id="246">   246  </span>		<span class="key">return</span> (n &gt;= <span class="num_const">0</span> &amp;&amp; n % <span class="num_const">1</span> == <span class="num_const">0</span>);
<span class="lineno" id="247">   247  </span>	}
<span class="lineno" id="248">   248  </span>
<span class="lineno" id="249">   249  </span>	<span class="comment doc">/**
<span class="lineno" id="250">   250  </span>	 * Returns a random number inside a specific range
<span class="lineno" id="251">   251  </span>	 * @param start (Number)
<span class="lineno" id="252">   252  </span>	 * @param end (Number)
<span class="lineno" id="253">   253  </span>	 * @return Number
<span class="lineno" id="254">   254  </span>	 */</span>	
<span class="lineno" id="255">   255  </span>	<span class="key">public</span> <span class="key">static</span> <span class="key">function</span> rnd(start:Number, end:Number):Number {
<span class="lineno" id="256">   256  </span>		<span class="key">return</span> Math.round( Math.random( ) * (end - start) ) + start;
<span class="lineno" id="257">   257  </span>	}
<span class="lineno" id="258">   258  </span>
<span class="lineno" id="259">   259  </span>	<span class="comment doc">/**
<span class="lineno" id="260">   260  </span>	 * Correct "roundoff errors" in floating point math.
<span class="lineno" id="261">   261  </span>	 * @param n (Number)
<span class="lineno" id="262">   262  </span>	 * @param precision (Number) - optional [default: returns (10000 * number) / 10000]
<span class="lineno" id="263">   263  </span>	 * @return Number
<span class="lineno" id="264">   264  </span>	 * @see {@link http://www.zeuslabs.us/2007/01/30/flash-floating-point-number-errors/} 
<span class="lineno" id="265">   265  </span>	 */</span>
<span class="lineno" id="266">   266  </span>	<span class="key">public</span> <span class="key">static</span> <span class="key">function</span> sanitizeFloat(n:Number, precision:Number):Number {
<span class="lineno" id="267">   267  </span>		<span class="key">var</span> p:Number = (!precision) ? <span class="num_const">5</span> : int( precision );
<span class="lineno" id="268">   268  </span>		<span class="key">var</span> c:Number = Math.pow( <span class="num_const">10</span>, p );
<span class="lineno" id="269">   269  </span>		<span class="key">return</span> Math.round( c * n ) / c;
<span class="lineno" id="270">   270  </span>	}
<span class="lineno" id="271">   271  </span>
<span class="lineno" id="272">   272  </span>	<span class="comment doc">/**
<span class="lineno" id="273">   273  </span>	 * Evaluate if two numbers are nearly equal
<span class="lineno" id="274">   274  </span>	 * @param n1 (Number)
<span class="lineno" id="275">   275  </span>	 * @param n2 (Number)
<span class="lineno" id="276">   276  </span>	 * @param precision (Number) - optional [default: 0.00001 &lt;diff&gt; -0.00001]
<span class="lineno" id="277">   277  </span>	 * @return Boolean
<span class="lineno" id="278">   278  </span>	 * @see {@link http://www.zeuslabs.us/2007/01/30/flash-floating-point-number-errors/}
<span class="lineno" id="279">   279  </span>	 */</span>
<span class="lineno" id="280">   280  </span>	<span class="key">public</span> <span class="key">static</span> <span class="key">function</span> fuzzyEval(n1:Number, n2:Number, precision:Number):Boolean {
<span class="lineno" id="281">   281  </span>		<span class="key">var</span> d:Number = n1 - n2;
<span class="lineno" id="282">   282  </span>		<span class="key">var</span> p:Number = (!precision) ? <span class="num_const">5</span> : int( precision );
<span class="lineno" id="283">   283  </span>		<span class="key">var</span> r:Number = Math.pow( <span class="num_const">10</span>, -p );
<span class="lineno" id="284">   284  </span>		<span class="key">return</span> d &lt; r &amp;&amp; d &gt; -r;
<span class="lineno" id="285">   285  </span>	}	
<span class="lineno" id="286">   286  </span>
<span class="lineno" id="287">   287  </span>	<span class="key">private</span> <span class="key">function</span> MathBase() {
<span class="lineno" id="288">   288  </span>	}
<span class="lineno" id="289">   289  </span>}</pre><ul class="main_nav" id="main_nav"><li><a href="../../../overview-summary.html" title="Overview of SASAPI" class="button">Overview</a></li><li><a href="package-summary.html" title="Overview of package com.sekati.math" class="button">Package</a></li><li><a href="MathBase.html" title="Detail of com.sekati.math.MathBase API" class="button">Class</a></li><li><span class="button nav_current">Source</span></li><li><a href="../../../index-files/index.html" title="Alpabetical index of types and members" class="button">Index</a></li></ul><div class="footer"><a href="http://www.badgers-in-foil.co.uk/projects/as2api/" title="ActionScript 2 API Documentation Generator">as2api</a></div></body></html>